﻿
using B.S.DataBase.MyProject.Domain.DiagnosisAndTreatmentManagement;
using B.S.DataBase.MyProject.ErrorCode;
using B.S.DataBase.MyProject.Infrastructure;
using MediatR;
using MedicalPCTerminal.Read.API.Appcation.Commands.Management;

namespace MedicalPCTerminal.Read.API.Appcation.CommandHandlers.Management
{
    public class GetBoolCommandHandler : IRequestHandler<GetBoolCommand, APIResult<CollectionManagement>>
    {
        private readonly SqlSugarContext sqlSugar;

        public GetBoolCommandHandler(SqlSugarContext sqlSugar)
        {
            this.sqlSugar = sqlSugar;
        }
        public async Task<APIResult<CollectionManagement>> Handle(GetBoolCommand request, CancellationToken cancellationToken)
        {
            try
            {
                APIResult<CollectionManagement> result = new APIResult<CollectionManagement>();
                var entity = sqlSugar.db.Queryable<CollectionManagement>().Where(x => x.UserId == request.UserId).First();
                if (entity != null)
                {
                    result.Code = APIEnum.查询成功;
                    result.Msg = APIEnum.查询成功.ToString();
                    result.data = entity;
                }
                else
                {
                    result.Code = APIEnum.查询失败;
                    result.Msg = APIEnum.查询失败.ToString();
                }
                return await Task.FromResult(result);
            }
            catch (Exception)
            {

                throw;
            }
        }
    }
}
